#!/bin/sh
# This currently contains a script file which you can modify
# if required to satisfy your requirements.
# You need to install two programs for this script to run:
#
#    Zenity which is a program that will display GTK+ dialogs,
#    and returns (either in the return code, or on standard output)
#    the users input. This allows you to present information, and ask
#    for information from shell scripts. You can set timers if required.
#
#    Sox allows you to play an audio file as a warning -
#    you may need an extra library if you use mp3.
#
# Zenity and Sox can installed by
#    sudo apt-get install sox libsox-fmt-mp3 zenity
#
# Modifications to this script are likely to be overwritten by
# updates so back it up


# Put up a warning with timer using Zenity
zenity --question --text="The Battery Level is dangerously low - the machine will be suspended shortly" --timeout=40 --ok-label="Suspend Immediately" --cancel-label="Abort Suspension" --title=WARNING_SUSPENDING_SHORTLY --window-icon=error --height=400 --width=750
rc=$?

if [ $rc = "0" ] || [ $rc = "5" ]; then
# Put up another warning which will be there when machine is restarted,
zenity --warning --text="Machine was Suspended as the battery level was dangerously low" &
# wait a few seconds to stabilise then suspend.
# sleep 2
# Suspend via dbus in Mint 17.x follows
dbus-send --print-reply --system --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Suspend
# Suspend via systemctl in Mint 18 - Mint 20 follows
systemctl suspend
exit 1
fi
exit 0
# Modified 08-12-2022 to cleanup suspendScript
# Modified 07-07-2016 for Mint 18 using systemctl calls for suspend and added option of Suspend Immediately
# Modified 15-07-2016 to correct messages and spelling.
# Modified 27-07-2017 to remove sound file which is transfered to applet

